package com.example.springdemo;

import cn.hutool.core.util.XmlUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.springdemo.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static cn.hutool.core.util.XmlUtil.*;

@Slf4j
public class SomeClass {
    static String  xml = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
            "   <soap:Body>\n" +
            "      <ns1:hrpCommIofResponse xmlns:ns1=\"http://his.server.webservice.chd.com\">\n" +
            "         <ns1:out>{\"prm_outputdata\":[{\"BAR_CODE\":\"1729063010102EL8\",\"BATCH_NO\":\"102EL8\",\"CERT_CODE\":\"国械注进20203021529\",\"CHARGE_CODE\":\"34799\",\"CHARGE_NAME\":\"可吸收缝线-VCP397H  4/0 美国\",\"CURR_AMOUNT\":365,\"IMME_AMOUNT\":365,\"INV_CODE\":\"020210000135\",\"INV_NAME\":\"可吸收性缝线(商品名：VICRYL Plus)\",\"STORE_CODE\":\"201\"}],\"prm_responsecode\":\"00\"}</ns1:out>\n" +
            "      </ns1:hrpCommIofResponse>\n" +
            "   </soap:Body>\n" +
            "</soap:Envelope>";

    static String xml1 ="<users>\n" +
            "    <user userId=\"1\">\n" +
            "        <username>admin</username>\n" +
            "        <pwd>123</pwd>\n" +
            "    </user>\n" +
            "</users>" ;

    public static void main(String[] args) throws Exception {

//        getOut();
//        parse1();


        ArrayList<String> strings = Lists.newArrayList("zhangsan", "lisi", "wangwu");
//        strings.stream().forEach(System.out::println);
        List<String> collect = strings.stream().filter(s -> s == null).collect(Collectors.toList());
        System.out.println(collect.size());
    }

    private static void parse1() {
        // 解析xml 输出out
        try {
            Document document = DocumentHelper.parseText(xml);
            Element rootElement = document.getRootElement();
            System.out.println(rootElement.toString());
            Element bodyElement = rootElement.element("Body");
            Element responseElement = bodyElement.element("hrpCommIofResponse");
            Element outElement = responseElement.element("out");
            String outText = outElement.getText();
            JSONObject resObject = JSONObject.parseObject(outText);
            JSONArray prmOutputdata = resObject.getJSONArray("prm_outputdata");
            log.info("解析后的out内容: {}", prmOutputdata);
        } catch (Exception e) {
            log.error("解析XML时发生错误", e);
        }
    }

    private static String getOut() throws Exception{
        Document doc = DocumentHelper.parseText(xml1.replaceAll("\n", ""));

        Element rootElement = doc.getRootElement();
        Element element = rootElement.element("user");
        String userId = element.attributeValue("userId");
        String pwd = element.elementText("pwd");
        String username = element.elementText("username");
        System.out.println(username);
//        Node node = doc.selectSingleNode("//user[@userId='1']/username");
//        System.out.println(node.getText());
        return  null;
    }

}



